package com.hyz.listener;

import com.alibaba.fastjson.JSON;
import com.hyz.pojo.AssetLog;
import com.hyz.service.AssetLogService;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author HGD
 * @date 2022/10/8 16:34
 */
@Component
public class AssetLogListener {
    @Autowired
    private AssetLogService service;

    @RabbitHandler
    @RabbitListener(queuesToDeclare = @Queue("assetLog"))
    public void insertAssetLog(String message) {
        AssetLog assetLog = JSON.parseObject(message, AssetLog.class);
        service.save(assetLog);
    }
}
